package com.max.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.max.base.BaseController;
import com.max.common.R;
import com.max.entity.RoomReservation;
import com.max.service.IRoomReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

@Api(tags = "会议室预约相关")
@RequestMapping(value = "/roomReservation")
@RestController
public class RoomReservationController extends BaseController {


    @Autowired
    private IRoomReservationService roomReservationService;

    @ApiOperation("查询会议室预约列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R<List<RoomReservation>> list(RoomReservation roomReservation) {
        startPage();
        List<RoomReservation> list = roomReservationService.list(new LambdaQueryWrapper<RoomReservation>()
                .eq(!Objects.isNull(roomReservation.getUserId()), RoomReservation::getUserId, roomReservation.getUserId())
                .eq(!Objects.isNull(roomReservation.getRoomId()), RoomReservation::getRoomId, roomReservation.getRoomId())
                .eq(!Objects.isNull(roomReservation.getUseDate()), RoomReservation::getUseDate, roomReservation.getUseDate())
                .eq(!Objects.isNull(roomReservation.getTimeNum()), RoomReservation::getTimeNum, roomReservation.getTimeNum())
        );
        return R.ok(list);
    }

    @ApiOperation("添加会议室预约")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public R<?> addRoomReservation(@RequestBody RoomReservation roomReservation) {
        return R.result(roomReservationService.save(roomReservation));
    }

    @ApiOperation("更新会议室预约")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public R<?> updateRoomReservation(@RequestBody RoomReservation roomReservation) {
        return R.result(roomReservationService.updateById(roomReservation));
    }

    @ApiOperation("删除会议室预约")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public R<?> deleteRoomReservation(@RequestBody RoomReservation roomReservation) {
        return R.result(roomReservationService.removeById(roomReservation));
    }


}
